package com.trantor.stockmarketwatch.tests;

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import com.trantor.stockmarketwatch.StockEntry;
import com.trantor.stockmarketwatch.StockEntryParser;

import junit.framework.TestCase;

public class ParserTests extends TestCase {
	
	public void testGoogleParser() throws IOException, SAXException, ParserConfigurationException {
		final String xml = 
			"<xml_api_reply version='1'>" +
				"<finance module_id='0' tab_id='0' mobile_row='0' mobile_zipped='1' row='0' section='0'>" +
					"<symbol data='YHOO'/>" +
					"<pretty_symbol data='YHOO'/>" +
					"<symbol_lookup_url data='/finance?client=ig(and)q=YHOO'/>" +
					"<company data='Yahoo! Inc.'/>" +
					"<exchange data='Nasdaq'/>" +
					"<exchange_timezone data='ET'/>" +
					"<exchange_utc_offset data='+05:00'/>" +
					"<exchange_closing data='960'/>" +
					"<divisor data='2'/>" +
					"<currency data='USD'/>" +
					"<last data='31.03'/>" +
					"<high data='31.05'/>" +
					"<low data='30.34'/>" +
					"<volume data='12795013'/>" +
					"<avg_volume data='13017'/>" +
					"<market_cap data='31660.56'/>" +
					"<open data='30.53'/>" +
					"<y_close data='30.43'/>" +
					"<change data='+0.60'/>" +
					"<perc_change data='1.95'/>" +
					"<delay data='0'/>" +
					"<trade_timestamp data='5 hours ago'/>" +
					"<trade_date_utc data='20130919'/>" +
					"<trade_time_utc data='200007'/>" +
					"<current_date_utc data='20130920'/>" +
					"<current_time_utc data='013120'/>" +
					"<symbol_url data='/finance?client=ig(and)q=YHOO'/>" +
					"<chart_url data='/finance/chart?q=NASDAQ:YHOO(and)tlf=12'/>" +
					"<disclaimer_url data='/help/stock_disclaimer.html'/>" +
					"<ecn_url data=''/>" +
					"<isld_last data='30.98'/>" +
					"<isld_trade_date_utc data='20130919'/>" +
					"<isld_trade_time_utc data='235946'/>" +
					"<brut_last data=''/>" +
					"<brut_trade_date_utc data=''/>" +
					"<brut_trade_time_utc data=''/>" +
					"<daylight_savings data='true'/>" +
				"</finance>" +
			"</xml_api_reply>";
		
		StockEntry se = StockEntryParser.parseGoogleStockEntry(xml);
		
		assertEquals("YHOO", se.getTicker());
		assertEquals("31.03", se.getPrice());
		assertEquals("+0.60", se.getChange());
		assertEquals("1.95", se.getPercent_change());
	}

}
